package net.sashag.nadlandroid;

import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.apps.analytics.easytracking.TrackedActivity;
import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.Bean;
import com.googlecode.androidannotations.annotations.Click;
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.annotations.Extra;
import com.googlecode.androidannotations.annotations.ViewById;
import com.parse.ParseUser;

@EActivity(R.layout.smallaptdetails)
public class SmallApartmentDetailsActivity extends TrackedActivity {

	@Bean protected FavoritesManager favoritesManager;
	
	@Extra("Apartment") protected Apartment apartment;
	
	@ViewById protected TextView txtUnpublished;
	@ViewById protected TextView txtAddress;
	@ViewById protected TextView txtDetails;
	
	@AfterViews
	protected void setupUi() {
		setTitle("Apartment Details");
		if (!apartment.isPublished()) {
			txtUnpublished.setVisibility(View.VISIBLE);
		}
		txtAddress.setText(apartment.getAddress());
		txtDetails.setText(String.format("Bedrooms: %d\nPrice: %d\n\n", apartment.getBedrooms(), apartment.getPrice()));
	}
	
	@Click(R.id.btnAddToFavorites)
	protected void onAddToFavoritesClicked() {
		ParseUser currentUser = ParseUser.getCurrentUser();
		favoritesManager.addToFavorites(apartment, currentUser);
		Toast.makeText(this, "Added to favorites", Toast.LENGTH_SHORT).show();
	}
	
	@Click(R.id.btnShowDetails)
	protected void onShowDetailsClicked() {
		new ApartmentDetailsActivity_.IntentBuilder_(this).apartment(apartment).start();
	}
	
	@Click(R.id.btnContactOwner)
	protected void onContactOwnerClicked() {
		apartment.showContactOptions(this);
	}
}
